//JavaScript Framework 2.0 Code
try {
	Type.registerNamespace('com.yyuap.standard.StudentDetailController');
	com.yyuap.standard.StudentDetailController = function() {
		com.yyuap.standard.StudentDetailController.initializeBase(this);
		this.initialize();
	}
	function com$yyuap$standard$StudentDetailController$initialize() {
		//you can programing by $ctx API
		//get the context data through $ctx.get()
		//set the context data through $ctx.push(json)
		//set the field of the context through $ctx.put(fieldName, fieldValue)
		//get the parameter of the context through $ctx.param(parameterName)
		//Demo Code:
		//    var str = $ctx.getString();      //获取当前Context对应的字符串
		//    alert($ctx.getString())          //alert当前Context对应的字符串
		//    var json = $ctx.getJSONObject(); //获取当前Context，返回值为json
		//    json["x"] = "a";        //为当前json增加字段
		//    json["y"] = [];           //为当前json增加数组
		//    $ctx.push(json);            //设置context，并自动调用数据绑定
		//
		//    put方法需手动调用databind()
		//    var x = $ctx.get("x");    //获取x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.put("x", "b");     //设置x字段值
		//    $ctx.databind();            //调用数据绑定才能将修改的字段绑定到控件上
		//    var p1 = $param.getString("p1");   //获取参数p2的值，返回一个字符串
		//    var p2 = $param.getJSONObject("p2");   //获取参数p3的值，返回一个JSON对象
		//    var p3 = $param.getJSONArray("p3");   //获取参数p1的值，返回一个数组

		//your initialize code below...

	}

	function com$yyuap$standard$StudentDetailController$evaljs(js) {
		eval(js)
	}

	function com$yyuap$standard$StudentDetailController$button0_onclick(sender, args) {
		$view.open({
			"viewid" : "com.yyuap.standard.StudentList", //目标页面（首字母大写）全名，
			"isKeep" : "false"
		});
	}

	var flag;
	var id;
	function com$yyuap$standard$StudentDetailController$button1_onclick(sender, args) {
		$ctx.dataCollect();
		var data = $ctx.getJSONObject();
		if (data) {
			if (flag == "edit") {
				updateData(data);
			} else if (flag == "add") {
				addData(data);
			}
		}
	}

	function updateData(data) {
		$ctx.dataCollect();
		var userInfor = $ctx.getJSONObject();
		$service.callAction({
			"viewid" : "com.yyuap.standard.service.StandardController", //后台Controller(带包名)的类名
			"action" : "updateData", //后台Controller的方法名,
			"userInfor" : userInfor, //自定义参数
			"id" : id,
			"callback" : "updateCallBack()", //请求成功后回调js方法
			"error" : "updateErrCallBack()"//请求失败回调的js方法
		})
	}

	function updateCallBack() {

		var flag2 = $ctx.getString("flag");
		var des = $ctx.getString("des");

		if (flag2 == "success") {
			$toast("更新成功！");
			$view.open({
				"viewid" : "com.yyuap.standard.StudentList", //目标页面（首字母大写）全名，
				"isKeep" : "false"
			});
		} else {
			$alert(des);
		}
	}

	function updateErrCallBack() {
		$alert("更新数据失败");
	}

	function addData(data) {
		$ctx.dataCollect();
		var userInfor = $ctx.getJSONObject();
		$service.callAction({
			"viewid" : "com.yyuap.standard.service.StandardController", //后台Controller(带包名)的类名
			"action" : "addData", //后台Controller的方法名,
			"userInfor" : userInfor, //自定义参数
			"callback" : "addCallBack()", //请求成功后回调js方法
			"error" : "addErrCallBack()"//请求失败回调的js方法
		})
	}

	function addCallBack() {

		var flag1 = $ctx.getString("flag");
		var des = $ctx.getString("des");

		if (flag1 == "success") {
			$toast("添加成功！");
			$view.open({
				"viewid" : "com.yyuap.standard.StudentList", //目标页面（首字母大写）全名，
				"isKeep" : "false"
			});
		} else {
			$alert(des);
		}

	}

	function addErrCallBack() {
		$alert("删除数据失败");
	}

	function loadData(sender, args) {
		flag = $param.getString("flag");

		if (flag == "edit") {
			var row = $param.getJSONObject("row");
			id = row.id;
			$ctx.push(row);
		}
	}


	com.yyuap.standard.StudentDetailController.prototype = {
		button1_onclick : com$yyuap$standard$StudentDetailController$button1_onclick,
		button0_onclick : com$yyuap$standard$StudentDetailController$button0_onclick,
		initialize : com$yyuap$standard$StudentDetailController$initialize,
		evaljs : com$yyuap$standard$StudentDetailController$evaljs
	};
	com.yyuap.standard.StudentDetailController.registerClass('com.yyuap.standard.StudentDetailController', UMP.UI.Mvc.Controller);
} catch(e) {
	$e(e);
}
